import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

// 配置vuex持久化
import VuexPersistence from 'vuex-persist'

const vuexLocal = new VuexPersistence({
    storage: window.sessionStorage,
	key: "zh_vuex"
})

export default new Vuex.Store({
  state: {
	// 用户登录的token值
	token: "",
	// 用户登录的基本信息
	userMsg: {},
	// 页面加载的loading效果
	isLoading: false,
	// 保存面包屑
	bread: [],
  },
  mutations: {
	// 保存用户信息
	setUserMsg(state,data) {
		state.token = data.token;
		state.userMsg = data;
	},
	// 退出登录的操作
	layout(state) {
		state.token = "";
		state.userMsg = {};
	},
	// 设置页面加载的loading效果
	setLoading(state,status) {
		state.isLoading = status;
	},
	// 设置动态面包屑
	setBread(state,bread) {
		state.bread = bread;
	}
  },
  getters: {

  },
  plugins: [vuexLocal.plugin]
})
